﻿Imports Microsoft.Win32
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Namespace System.Workflow.ComponentModel.Design
    Public Class AmbientTheme
        Inherits DesignerTheme
        ' Methods
        Public Sub New(ByVal theme As WorkflowTheme)
            MyBase.New(theme)
            Me.showConfigErrors = True
            Me.dropIndicatorColor = Color.Green
            Me.selectionForeColor = Color.Blue
            Me.selectionPatternColor = Color.DarkGray
            Me.foreColor = Color.Gray
            Me.backColor = Color.White
            Me.commentIndicatorColor = Color.FromArgb(&H31, &HC6, &H69)
            Me.readonlyIndicatorColor = Color.Gray
            Me.watermarkAlignment = DesignerContentAlignment.BottomRight
            Me.watermarkImagePath = String.Empty
            Me.gridStyle = DashStyle.Dash
            Me.gridColor = Color.FromArgb(&HC0, &HC0, &HC0)
            Me.fontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
            Me.designerStyle = DesignerSize.Medium
            Me.drawRounded = True
            Me.showDesignerBorder = True
        End Sub

        Private Sub ApplySystemColors()
            Me.DropIndicatorColor = SystemColors.HotTrack
            Me.SelectionForeColor = SystemColors.Highlight
            Me.SelectionPatternColor = SystemColors.Highlight
            Me.ForeColor = SystemColors.WindowText
            Me.CommentIndicatorColor = SystemColors.GrayText
            Me.ReadonlyIndicatorColor = SystemColors.GrayText
            Me.BackColor = SystemColors.Window
            Me.GridColor = SystemColors.InactiveBorder
            Me.FontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
        End Sub

        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try 
                Me.UseOperatingSystemSettings = False
                If (Not Me.font Is Nothing) Then
                    Me.font.Dispose
                    Me.font = Nothing
                End If
                If (Not Me.boldFont Is Nothing) Then
                    Me.boldFont.Dispose
                    Me.boldFont = Nothing
                End If
                If (Not Me.watermarkImage Is Nothing) Then
                    Me.watermarkImage.Dispose
                    Me.watermarkImage = Nothing
                End If
                If (Not Me.foregroundPen Is Nothing) Then
                    Me.foregroundPen.Dispose
                    Me.foregroundPen = Nothing
                End If
                If (Not Me.foregroundBrush Is Nothing) Then
                    Me.foregroundBrush.Dispose
                    Me.foregroundBrush = Nothing
                End If
                If (Not Me.backgroundBrush Is Nothing) Then
                    Me.backgroundBrush.Dispose
                    Me.backgroundBrush = Nothing
                End If
                If (Not Me.dropIndicatorPen Is Nothing) Then
                    Me.dropIndicatorPen.Dispose
                    Me.dropIndicatorPen = Nothing
                End If
                If (Not Me.selectionPatternPen Is Nothing) Then
                    Me.selectionPatternPen.Dispose
                    Me.selectionPatternPen = Nothing
                End If
                If (Not Me.selectionForegroundPen Is Nothing) Then
                    Me.selectionForegroundPen.Dispose
                    Me.selectionForegroundPen = Nothing
                End If
                If (Not Me.majorGridPen Is Nothing) Then
                    Me.majorGridPen.Dispose
                    Me.majorGridPen = Nothing
                End If
                If (Not Me.majorGridBrush Is Nothing) Then
                    Me.majorGridBrush.Dispose
                    Me.majorGridBrush = Nothing
                End If
                If (Not Me.minorGridPen Is Nothing) Then
                    Me.minorGridPen.Dispose
                    Me.minorGridPen = Nothing
                End If
                If (Not Me.minorGridBrush Is Nothing) Then
                    Me.minorGridBrush.Dispose
                    Me.minorGridBrush = Nothing
                End If
                If (Not Me.commentIndicatorPen Is Nothing) Then
                    Me.commentIndicatorPen.Dispose
                    Me.commentIndicatorPen = Nothing
                End If
                If (Not Me.commentIndicatorBrush Is Nothing) Then
                    Me.commentIndicatorBrush.Dispose
                    Me.commentIndicatorBrush = Nothing
                End If
                If (Not Me.readonlyIndicatorBrush Is Nothing) Then
                    Me.readonlyIndicatorBrush.Dispose
                    Me.readonlyIndicatorBrush = Nothing
                End If
                If (Not Me.dropIndicatorBrush Is Nothing) Then
                    Me.dropIndicatorBrush.Dispose
                    Me.dropIndicatorBrush = Nothing
                End If
                If (Not Me.selectionForegroundBrush Is Nothing) Then
                    Me.selectionForegroundBrush.Dispose
                    Me.selectionForegroundBrush = Nothing
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        Friend Overrides Function GetPropertyValues(ByVal context As ITypeDescriptorContext) As ICollection
            Dim objArray As Object() = New Object(0  - 1) {}
            If String.Equals(context.PropertyDescriptor.Name, "GridStyle", StringComparison.Ordinal) Then
                objArray = New Object() { DashStyle.Solid, DashStyle.Dash, DashStyle.Dot }
            End If
            Return objArray
        End Function

        Public Overrides Sub Initialize()
            MyBase.Initialize
            If Me.useOperatingSystemSettings Then
                Me.ApplySystemColors
            End If
        End Sub

        Public Overrides Sub OnAmbientPropertyChanged(ByVal ambientProperty As AmbientProperty)
            MyBase.OnAmbientPropertyChanged(ambientProperty)
            If (ambientProperty = AmbientProperty.DesignerSize) Then
                Me.DropIndicatorColor = Me.dropIndicatorColor
                Me.FontName = Me.fontName
            ElseIf (ambientProperty = AmbientProperty.OperatingSystemSetting) Then
                Me.ApplySystemColors
            End If
        End Sub

        Private Sub OnOperatingSystemSettingsChanged(ByVal sender As Object, ByVal e As UserPreferenceChangedEventArgs)
            If ((e.Category = UserPreferenceCategory.Color) OrElse (e.Category = UserPreferenceCategory.VisualStyle)) Then
                MyBase.ContainingTheme.AmbientPropertyChanged(AmbientProperty.OperatingSystemSetting)
                WorkflowTheme.FireThemeChange
            End If
        End Sub

        Friend Sub UpdateFont()
            If Me.useDefaultFont Then
                Dim readOnly As Boolean = MyBase.ReadOnly
                MyBase.ReadOnly = False
                Me.FontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
                MyBase.ReadOnly = [readOnly]
            End If
        End Sub

        Friend Sub UseDefaultFont()
            Me.useDefaultFont = True
        End Sub


        ' Properties
        <Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), TypeConverter(GetType(ColorPickerConverter)), SRDescription("WorkflowBackgroundDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(13)> _
        Public Overridable Property BackColor As Color
            Get
                Return Me.backColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.backColor = value
                If (Not Me.backgroundBrush Is Nothing) Then
                    Me.backgroundBrush.Dispose
                    Me.backgroundBrush = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property BackgroundBrush As Brush
            Get
                If (Me.backgroundBrush Is Nothing) Then
                    Me.backgroundBrush = New SolidBrush(Me.backColor)
                End If
                Return Me.backgroundBrush
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property BoldFont As Font
            Get
                If (Me.boldFont Is Nothing) Then
                    If ((Me.fontName Is Nothing) OrElse (Me.fontName.Length = 0)) Then
                        Me.fontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
                    End If
                    Dim list As New ArrayList(AmbientTheme.SupportedFonts)
                    If Not list.Contains(Me.fontName) Then
                        Me.fontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
                    End If
                    Me.boldFont = New Font(Me.fontName, Me.FontSize, FontStyle.Bold)
                End If
                Return Me.boldFont
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public Overridable ReadOnly Property BorderWidth As Integer
            Get
                Return AmbientTheme.BorderWidths(CInt(MyBase.ContainingTheme.AmbientTheme.DesignerSize))
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property CommentIndicatorBrush As Brush
            Get
                If (Me.commentIndicatorBrush Is Nothing) Then
                    Me.commentIndicatorBrush = New SolidBrush(Color.FromArgb(40, Me.commentIndicatorColor))
                End If
                Return Me.commentIndicatorBrush
            End Get
        End Property

        <SRDescription("CommentColorDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), TypeConverter(GetType(ColorPickerConverter)), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(11)> _
        Public Overridable Property CommentIndicatorColor As Color
            Get
                Return Me.commentIndicatorColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.commentIndicatorColor = value
                If (Not Me.commentIndicatorPen Is Nothing) Then
                    Me.commentIndicatorPen.Dispose
                    Me.commentIndicatorPen = Nothing
                End If
                If (Not Me.commentIndicatorBrush Is Nothing) Then
                    Me.commentIndicatorBrush.Dispose
                    Me.commentIndicatorBrush = Nothing
                End If
            End Set
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property CommentIndicatorPen As Pen
            Get
                If (Me.commentIndicatorPen Is Nothing) Then
                    Me.commentIndicatorPen = New Pen(Me.commentIndicatorColor, 1!)
                End If
                Return Me.commentIndicatorPen
            End Get
        End Property

        <SRCategory("ActivityAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), SRDescription("DesignerSizeDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), DefaultValue(1), DispId(20), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public Overridable Property DesignerSize As DesignerSize
            Get
                Return Me.designerStyle
            End Get
            Set(ByVal value As DesignerSize)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.designerStyle = value
                MyBase.ContainingTheme.AmbientPropertyChanged(AmbientProperty.DesignerSize)
            End Set
        End Property

        <SRCategory("WorkflowAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(6), DefaultValue(False), SRDescription("GrayscaleWorkflowDesc", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property DrawGrayscale As Boolean
            Get
                Return Me.drawGrayscale
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.drawGrayscale = value
            End Set
        End Property

        <DefaultValue(True), SRCategory("ActivityAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(&H15), SRDescription("DrawRoundedDesignersDesc", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property DrawRounded As Boolean
            Get
                Return Me.drawRounded
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.drawRounded = value
            End Set
        End Property

        <SRDescription("WorkflowShadowDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("WorkflowAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(14), DefaultValue(False)> _
        Public Overridable Property DrawShadow As Boolean
            Get
                Return Me.drawShadow
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.drawShadow = value
            End Set
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property DropIndicatorBrush As Brush
            Get
                If (Me.dropIndicatorBrush Is Nothing) Then
                    Me.dropIndicatorBrush = New SolidBrush(Me.dropIndicatorColor)
                End If
                Return Me.dropIndicatorBrush
            End Get
        End Property

        <SRDescription("DropHiliteDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), TypeConverter(GetType(ColorPickerConverter)), DispId(7)> _
        Public Overridable Property DropIndicatorColor As Color
            Get
                Return Me.dropIndicatorColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.dropIndicatorColor = value
                If (Not Me.dropIndicatorPen Is Nothing) Then
                    Me.dropIndicatorPen.Dispose
                    Me.dropIndicatorPen = Nothing
                End If
                If (Not Me.dropIndicatorBrush Is Nothing) Then
                    Me.dropIndicatorBrush.Dispose
                    Me.dropIndicatorBrush = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property DropIndicatorPen As Pen
            Get
                If (Me.dropIndicatorPen Is Nothing) Then
                    Me.dropIndicatorPen = New Pen(Me.dropIndicatorColor, CSng(Me.BorderWidth))
                End If
                Return Me.dropIndicatorPen
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property DropIndicatorSize As Size
            Get
                Return AmbientTheme.DropIndicatorSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property Font As Font
            Get
                If (Me.font Is Nothing) Then
                    If ((Me.fontName Is Nothing) OrElse (Me.fontName.Length = 0)) Then
                        Me.fontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
                    End If
                    Dim list As New ArrayList(AmbientTheme.SupportedFonts)
                    If Not list.Contains(Me.fontName) Then
                        Me.fontName = WorkflowTheme.GetDefaultFont.FontFamily.Name
                    End If
                    Me.font = New Font(Me.fontName, Me.FontSize)
                End If
                Return Me.font
            End Get
        End Property

        <TypeConverter(GetType(FontFamilyConverter)), SRDescription("FontDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(1), SRCategory("WorkflowAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property FontName As String
            Get
                Return Me.fontName
            End Get
            Set(ByVal value As String)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                If ((value Is Nothing) OrElse (value.Length = 0)) Then
                    Throw New Exception(DR.GetString("EmptyFontFamilyNotSupported", New Object(0  - 1) {}))
                End If
                Try 
                    Dim font As New Font(value, Me.FontSize)
                    If (Not font Is Nothing) Then
                        font.Dispose
                    End If
                Catch exception As Exception
                    Throw New Exception(DR.GetString("FontFamilyNotSupported", New Object() { value }), exception)
                End Try
                Me.fontName = value
                If (Not Me.font Is Nothing) Then
                    Me.font.Dispose
                    Me.font = Nothing
                End If
                If (Not Me.boldFont Is Nothing) Then
                    Me.boldFont.Dispose
                    Me.boldFont = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Private ReadOnly Property FontSize As Single
            Get
                If Me.useOperatingSystemSettings Then
                    Return SystemInformation.MenuFont.SizeInPoints
                End If
                Return AmbientTheme.FontSizes(CInt(Me.DesignerSize))
            End Get
        End Property

        Private Shared ReadOnly Property FontSizes As Single()
            Get
                If (AmbientTheme.fontSizes Is Nothing) Then
                    AmbientTheme.fontSizes = New Single() { (WorkflowTheme.GetDefaultFont.SizeInPoints - 2!), WorkflowTheme.GetDefaultFont.SizeInPoints, (WorkflowTheme.GetDefaultFont.SizeInPoints + 2!) }
                End If
                Return AmbientTheme.fontSizes
            End Get
        End Property

        <TypeConverter(GetType(ColorPickerConverter)), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), DispId(10), SRDescription("WorkflowForegroundDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property ForeColor As Color
            Get
                Return Me.foreColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.foreColor = value
                If (Not Me.foregroundPen Is Nothing) Then
                    Me.foregroundPen.Dispose
                    Me.foregroundPen = Nothing
                End If
                If (Not Me.foregroundBrush Is Nothing) Then
                    Me.foregroundBrush.Dispose
                    Me.foregroundBrush = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property ForegroundBrush As Brush
            Get
                If (Me.foregroundBrush Is Nothing) Then
                    Me.foregroundBrush = New SolidBrush(Me.foreColor)
                End If
                Return Me.foregroundBrush
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property ForegroundPen As Pen
            Get
                If (Me.foregroundPen Is Nothing) Then
                    Me.foregroundPen = New Pen(Me.foreColor, 1!)
                    Me.foregroundPen.DashStyle = DashStyle.Dot
                End If
                Return Me.foregroundPen
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overridable ReadOnly Property GlyphSize As Size
            Get
                Return AmbientTheme.GlyphSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), TypeConverter(GetType(ColorPickerConverter)), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), DispId(&H13), SRDescription("GridColorDesc", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property GridColor As Color
            Get
                Return Me.gridColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.gridColor = value
                If (Not Me.majorGridPen Is Nothing) Then
                    Me.majorGridPen.Dispose
                    Me.majorGridPen = Nothing
                End If
                If (Not Me.majorGridBrush Is Nothing) Then
                    Me.majorGridBrush.Dispose
                    Me.majorGridBrush = Nothing
                End If
                If (Not Me.minorGridPen Is Nothing) Then
                    Me.minorGridPen.Dispose
                    Me.minorGridPen = Nothing
                End If
                If (Not Me.minorGridBrush Is Nothing) Then
                    Me.minorGridBrush.Dispose
                    Me.minorGridBrush = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overridable ReadOnly Property GridSize As Size
            Get
                Return AmbientTheme.GridSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <DefaultValue(1), DispId(&H12), SRDescription("GridStyleDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property GridStyle As DashStyle
            Get
                Return Me.gridStyle
            End Get
            Set(ByVal value As DashStyle)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.gridStyle = value
                If (Not Me.majorGridPen Is Nothing) Then
                    Me.majorGridPen.Dispose
                    Me.majorGridPen = Nothing
                End If
                If (Not Me.minorGridPen Is Nothing) Then
                    Me.minorGridPen.Dispose
                    Me.minorGridPen = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Friend ReadOnly Property MagnifierSize As Size
            Get
                Return AmbientTheme.MagnifierSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property MajorGridBrush As Brush
            Get
                If (Me.majorGridBrush Is Nothing) Then
                    Me.majorGridBrush = New SolidBrush(Me.gridColor)
                End If
                Return Me.majorGridBrush
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property MajorGridPen As Pen
            Get
                If (Me.majorGridPen Is Nothing) Then
                    Me.majorGridPen = New Pen(Me.gridColor, 1!)
                    Me.majorGridPen.DashStyle = DashStyle.Dash
                End If
                Return Me.majorGridPen
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overridable ReadOnly Property Margin As Size
            Get
                Return AmbientTheme.MarginSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property MinorGridBrush As Brush
            Get
                If (Me.minorGridBrush Is Nothing) Then
                    Dim color As Color = Color.FromArgb(Me.gridColor.A, Math.Min((Me.gridColor.R + &H20), &HFF), Math.Min((Me.gridColor.G + &H20), &HFF), Math.Min((Me.gridColor.B + &H20), &HFF))
                    Me.minorGridBrush = New SolidBrush(color)
                End If
                Return Me.minorGridBrush
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property MinorGridPen As Pen
            Get
                If (Me.minorGridPen Is Nothing) Then
                    Dim color As Color = Color.FromArgb(Me.gridColor.A, Math.Min((Me.gridColor.R + &H20), &HFF), Math.Min((Me.gridColor.G + &H20), &HFF), Math.Min((Me.gridColor.B + &H20), &HFF))
                    Me.minorGridPen = New Pen(color, 1!)
                    Me.minorGridPen.DashStyle = DashStyle.Dot
                End If
                Return Me.minorGridPen
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property ReadonlyIndicatorBrush As Brush
            Get
                If (Me.readonlyIndicatorBrush Is Nothing) Then
                    Me.readonlyIndicatorBrush = New SolidBrush(Color.FromArgb(20, Me.readonlyIndicatorColor))
                End If
                Return Me.readonlyIndicatorBrush
            End Get
        End Property

        <TypeConverter(GetType(ColorPickerConverter)), DispId(12), SRDescription("LockColorDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor))> _
        Public Overridable Property ReadonlyIndicatorColor As Color
            Get
                Return Me.readonlyIndicatorColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.readonlyIndicatorColor = value
                If (Not Me.readonlyIndicatorBrush Is Nothing) Then
                    Me.readonlyIndicatorBrush.Dispose
                    Me.readonlyIndicatorBrush = Nothing
                End If
            End Set
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property ScrollIndicatorSize As Size
            Get
                Return AmbientTheme.ScrollIndicatorSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <TypeConverter(GetType(ColorPickerConverter)), SRDescription("SelectionForegroundDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), DispId(8)> _
        Public Overridable Property SelectionForeColor As Color
            Get
                Return Me.selectionForeColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.selectionForeColor = value
                If (Not Me.selectionForegroundPen Is Nothing) Then
                    Me.selectionForegroundPen.Dispose
                    Me.selectionForegroundPen = Nothing
                End If
                If (Not Me.selectionForegroundBrush Is Nothing) Then
                    Me.selectionForegroundBrush.Dispose
                    Me.selectionForegroundBrush = Nothing
                End If
            End Set
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property SelectionForegroundBrush As Brush
            Get
                If (Me.selectionForegroundBrush Is Nothing) Then
                    Me.selectionForegroundBrush = New SolidBrush(Me.selectionForeColor)
                End If
                Return Me.selectionForegroundBrush
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property SelectionForegroundPen As Pen
            Get
                If (Me.selectionForegroundPen Is Nothing) Then
                    Me.selectionForegroundPen = New Pen(Me.selectionForeColor, 1!)
                End If
                Return Me.selectionForegroundPen
            End Get
        End Property

        <TypeConverter(GetType(ColorPickerConverter)), Editor(GetType(ColorPickerEditor), GetType(UITypeEditor)), DispId(9), SRDescription("SelectionPatternDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ForegroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property SelectionPatternColor As Color
            Get
                Return Me.selectionPatternColor
            End Get
            Set(ByVal value As Color)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.selectionPatternColor = value
                If (Not Me.selectionPatternPen Is Nothing) Then
                    Me.selectionPatternPen.Dispose
                    Me.selectionPatternPen = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property SelectionPatternPen As Pen
            Get
                If (Me.selectionPatternPen Is Nothing) Then
                    Me.selectionPatternPen = New Pen(Me.selectionPatternColor, 1!)
                    Me.selectionPatternPen.DashStyle = DashStyle.Dot
                End If
                Return Me.selectionPatternPen
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overridable ReadOnly Property SelectionSize As Size
            Get
                Return AmbientTheme.SelectionSizes(CInt(Me.designerStyle))
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property ShadowDepth As Integer
            Get
                If Not Me.drawShadow Then
                    Return 0
                End If
                Return 6
            End Get
        End Property

        <DefaultValue(True), DispId(3), SRCategory("WorkflowAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), SRDescription("ShowConfigErrorDesc", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property ShowConfigErrors As Boolean
            Get
                Return Me.showConfigErrors
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.showConfigErrors = value
            End Set
        End Property

        <DefaultValue(True), SRDescription("DesignerBorderDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("ActivityAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(&H18)> _
        Public Overridable Property ShowDesignerBorder As Boolean
            Get
                Return Me.showDesignerBorder
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.showDesignerBorder = value
            End Set
        End Property

        <DefaultValue(False), DispId(&H11), SRDescription("ShowGridDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property ShowGrid As Boolean
            Get
                Return Me.showGrid
            End Get
            Set(ByVal value As Boolean)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.showGrid = value
            End Set
        End Property

        Friend Shared ReadOnly Property SupportedFonts As String()
            Get
                Dim list As New ArrayList
                Dim family As FontFamily
                For Each family In FontFamily.Families
                    list.Add(family.Name)
                Next
                list.Sort(CaseInsensitiveComparer.Default)
                Return DirectCast(list.ToArray(GetType(String)), String())
            End Get
        End Property

        <DispId(2), SRDescription("TextQualityDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), SRCategory("WorkflowAppearanceCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DefaultValue(0)> _
        Public Overridable Property TextQuality As TextQuality
            Get
                Return Me.textQuality
            End Get
            Set(ByVal value As TextQuality)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.textQuality = value
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Property UseOperatingSystemSettings As Boolean
            Public Overridable Get
                Return Me.useOperatingSystemSettings
            End Get
            Friend Overridable Set(ByVal value As Boolean)
                Me.useOperatingSystemSettings = value
                If Me.useOperatingSystemSettings Then
                    AddHandler SystemEvents.UserPreferenceChanged, New UserPreferenceChangedEventHandler(AddressOf Me.OnOperatingSystemSettingsChanged)
                    Me.OnOperatingSystemSettingsChanged(Me, New UserPreferenceChangedEventArgs(UserPreferenceCategory.Color))
                Else
                    RemoveHandler SystemEvents.UserPreferenceChanged, New UserPreferenceChangedEventHandler(AddressOf Me.OnOperatingSystemSettingsChanged)
                End If
            End Set
        End Property

        <DefaultValue(12), SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), SRDescription("WatermarkAlignmentDesc", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(&H10)> _
        Public Overridable Property WatermarkAlignment As DesignerContentAlignment
            Get
                Return Me.watermarkAlignment
            End Get
            Set(ByVal value As DesignerContentAlignment)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                Me.watermarkAlignment = value
            End Set
        End Property

        <Editor(GetType(ImageBrowserEditor), GetType(UITypeEditor)), SRCategory("BackgroundCategory", "System.Workflow.ComponentModel.Design.DesignerResources"), DispId(15), SRDescription("WorkflowWatermarkDesc", "System.Workflow.ComponentModel.Design.DesignerResources")> _
        Public Overridable Property WatermarkImagePath As String
            Get
                Return Me.watermarkImagePath
            End Get
            Set(ByVal value As String)
                If MyBase.ReadOnly Then
                    Throw New InvalidOperationException(DR.GetString("ThemePropertyReadOnly", New Object(0  - 1) {}))
                End If
                If ((Not String.IsNullOrEmpty(value) AndAlso value.Contains(Path.DirectorySeparatorChar.ToString)) AndAlso Path.IsPathRooted(value)) Then
                    value = DesignerHelpers.GetRelativePath(MyBase.ContainingTheme.ContainingFileDirectory, value)
                    If Not DesignerHelpers.IsValidImageResource(Me, MyBase.ContainingTheme.ContainingFileDirectory, value) Then
                        Throw New InvalidOperationException(DR.GetString("Error_InvalidImageResource", New Object(0  - 1) {}))
                    End If
                End If
                Me.watermarkImagePath = value
                If (Not Me.watermarkImage Is Nothing) Then
                    Me.watermarkImage.Dispose
                    Me.watermarkImage = Nothing
                End If
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property WorkflowWatermarkImage As Image
            Get
                If ((Me.watermarkImage Is Nothing) AndAlso (Me.watermarkImagePath.Length > 0)) Then
                    Me.watermarkImage = DesignerHelpers.GetImageFromPath(Me, MyBase.ContainingTheme.ContainingFileDirectory, Me.watermarkImagePath)
                End If
                Return Me.watermarkImage
            End Get
        End Property


        ' Fields
        Friend Const ArcDiameter As Integer = 8
        Private backColor As Color
        Private backgroundBrush As Brush
        Private boldFont As Font
        Private Shared ReadOnly BorderWidths As Integer() = New Integer() { 1, 1, 3 }
        Private commentIndicatorBrush As Brush
        Private commentIndicatorColor As Color
        Private commentIndicatorPen As Pen
        Friend Shared ReadOnly ConfigErrorImage As Image = DR.GetImage("ConfigError")
        Private Const DefaultShadowDepth As Integer = 6
        Private designerStyle As DesignerSize
        Friend Shared ReadOnly DisabledBrush As Brush = New SolidBrush(Color.FromArgb(40, Color.Gray))
        Friend Shared ReadOnly DragImageIconSize As Size = New Size(&H10, &H10)
        Friend Shared ReadOnly DragImageMargins As Size = New Size(4, 4)
        Friend Shared ReadOnly DragImageTextSize As Size = New Size(100, 60)
        Private drawGrayscale As Boolean
        Private drawRounded As Boolean
        Private drawShadow As Boolean
        Private dropIndicatorBrush As Brush
        Private dropIndicatorColor As Color
        Friend Shared ReadOnly DropIndicatorImage As Image = DR.GetImage("DropShapeShort")
        Private dropIndicatorPen As Pen
        Private Shared ReadOnly DropIndicatorSizes As Size() = New Size() { New Size(8, 8), New Size(12, 12), New Size(&H10, &H10) }
        Friend Const DropShadowWidth As Integer = 4
        Friend Shared ReadOnly FadeBrush As Brush = New SolidBrush(Color.FromArgb(120, &HFF, &HFF, &HFF))
        Private font As Font
        Private fontName As String
        Private Shared fontSizes As Single() = Nothing
        Private foreColor As Color
        Private foregroundBrush As Brush
        Private foregroundPen As Pen
        Private Shared ReadOnly GlyphSizes As Size() = New Size() { New Size(10, 10), New Size(14, 14), New Size(&H12, &H12) }
        Private gridColor As Color
        Private Shared ReadOnly GridSizes As Size() = New Size() { New Size(30, 30), New Size(40, 40), New Size(60, 60) }
        Private gridStyle As DashStyle
        Friend Shared ReadOnly LockImage As Image = DR.GetImage("PreviewIndicator")
        Friend Shared ReadOnly MagnifierPen As Pen = New Pen(Color.Black, 2!)
        Private Shared ReadOnly MagnifierSizes As Size() = New Size() { New Size(50, 50), New Size(100, 100), New Size(150, 150) }
        Private majorGridBrush As Brush
        Private majorGridPen As Pen
        Private Shared ReadOnly MarginSizes As Size() = New Size() { New Size(2, 2), New Size(4, 4), New Size(6, 6) }
        Friend Const MaxShadowDepth As Integer = 8
        Friend Const MaxZoom As Integer = 400
        Private minorGridBrush As Brush
        Private minorGridPen As Pen
        Friend Const MinShadowDepth As Integer = 0
        Friend Const MinZoom As Integer = 10
        Friend Shared ReadOnly PageShadowBrush As Brush = New SolidBrush(Color.FromArgb(&H4B, &H4B, &H4B))
        Friend Shared ReadOnly ReadOnlyImage As Image = DR.GetImage("ReadOnly")
        Private readonlyIndicatorBrush As Brush
        Private readonlyIndicatorColor As Color
        Friend Shared ReadOnly ScrollIndicatorImage As Image = DR.GetImage("ArrowLeft")
        Private Shared ReadOnly ScrollIndicatorSizes As Size() = New Size() { New Size(&H18, &H18), New Size(&H20, &H20), New Size(40, 40) }
        Friend Const ScrollIndicatorTransparency As Single = 0.7!
        Friend Const ScrollUnit As Integer = &H19
        Private selectionForeColor As Color
        Private selectionForegroundBrush As Brush
        Private selectionForegroundPen As Pen
        Private selectionPatternColor As Color
        Private selectionPatternPen As Pen
        Private Shared ReadOnly SelectionSizes As Size() = New Size() { New Size(2, 2), New Size(4, 4), New Size(6, 6) }
        Private showConfigErrors As Boolean
        Private showDesignerBorder As Boolean
        Private showGrid As Boolean
        Friend Shared ReadOnly SmartTagBorderPen As Pen = New Pen(Color.Black, 1!)
        Private textQuality As TextQuality
        Friend Shared TransparentColor As Color = Color.FromArgb(&HFF, 0, &HFF)
        Private useDefaultFont As Boolean
        Private useOperatingSystemSettings As Boolean
        Private watermarkAlignment As DesignerContentAlignment
        Private watermarkImage As Image
        Private watermarkImagePath As String
        Friend Const WatermarkTransparency As Single = 0.25!
        Friend Shared ReadOnly WorkflowBorderPen As Pen = New Pen(Color.FromArgb(&H7F, &H9D, &HB9), 1!)
        Friend Shared ReadOnly WorkspaceBackgroundBrush As Brush = New SolidBrush(Color.FromArgb(&HEA, &HEA, &HEC))
    End Class
End Namespace

